#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QProcess>
#include <windows.h>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);


}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_pushButton_clicked()
{
    process = new QProcess;
    QObject::connect(process,SIGNAL(readyReadStandardOutput()),this,SLOT(receiver()));
    process->setProcessChannelMode(QProcess::MergedChannels);
    QStringList arguments;
    arguments << "http://p3.music.126.net/tBTNafgjNnTL1KlZMt7lVA==/18885211718935735.jpg" << "18885211718935735.jpg";
    process->start("C:/git/AutoUpdate/build-AutoUpdate-Desktop_Qt_5_14_2_MinGW_64_bit-Debug/Update/debug/Update.exe",arguments);
    if (!process->waitForStarted())
        qDebug() << "Make failed:" << process->errorString();
    else
        qDebug() << "Child Process Started. " << process->readAll();
    //    Sleep(1);
    //    QApplication::quit();
}

void MainWindow::receiver()
{
    char output[128];
    int ret = process->readLine(output,127);
    qDebug() << output;
    QString str = QString(output).remove("\r").remove("\n");
    if(str == "guanle"){
        QApplication::quit();
    }
}
